package net.biancheng.common.core.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import net.biancheng.bean.SysDept;
import net.biancheng.bean.SysMenu;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: lb
 * @date: 2023/11/1 9:52
 * @desc: TreeSelect下拉树结构
 **/
@Data
public class TreeSelect implements Serializable {

    /**
     * 节点ID
     */
    private Long id;

    /**
     *节点名称
     */
    private String label;

    /**
     * 子节点集合
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect() {
    }

    public TreeSelect(SysMenu menu){
        this.id = menu.getId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysDept dept){
        this.id = dept.getId();
        this.label = dept.getDeptName();
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

}
